package com.example.demo.contorller;

import com.example.demo.Bean.Result;
import com.example.demo.Utils.FileUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/upload")
@CrossOrigin
public class UploadController {

    @PostMapping("/uploadFile")
    @ApiOperation("上传文件")
    @CrossOrigin
    public Object uploadImage(@RequestParam("file") MultipartFile file, HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        String uploadPath = FileUtil.uploadFile(file);
        return new Result(200,uploadPath);
    }

    @PostMapping("/uploadFiles")
    @ApiOperation("上传多个文件")
    public Object uploadImages(@RequestParam("files") MultipartFile[] files) {
        List<String> uploadPaths = FileUtil.uploadFile(files);
        return new Result(1,uploadPaths);
    }




}
